import { Sprite } from "cc"
import { Vec3 } from "cc"
import { Color } from "cc"
import { Tween } from "cc"
import { _decorator, Component, Node } from "cc"
import ResManager from "../framework/ResManager"
import { instantiate } from "cc"
import { Prefab } from "cc"
const { ccclass, property } = _decorator

@ccclass("Test")
export class Test extends Component {
  start() {
    // new Tween(this.node)
    //   .to(3, { alpha:0},{onUpdate:()=>{
    //     console.log(this.node.alpha)
    //   }}) //,alpha:0
    //   .start()
    // this.node.alpha = 0.5

    // this.scheduleOnce(() => {
    //   this.node.alpha = 0.2
    // },4)

    // this.scheduleOnce(() => {
    //   let sprite = this.node.getComponent(Sprite)
    //   sprite.color = new Color(255,255,255, 120)
    //   sprite.colorA = 120
    // },2)
  }

  update(deltaTime: number) {
    this.onPlayBeAttackEffect(new Vec3(0,0))

  }

  private onPlayBeAttackEffect(pos: Vec3){
    ResManager.instance.loadRes("prefabs/game/effect/effect_beAttack", Prefab, (err, prefab: Prefab) => {
      // console.log("----onPlayBeAttackEffect-----")
      let node = instantiate(prefab)
      this.node.addChild(node)
      node.setPosition(pos)
      new Tween(node)
        .delay(1)
        .call(() => {
          node.destroy()
        })
        .start()
    })
  }
}
